package wiModel;

import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import wiBase.WiException;

import wiBase.WiObject;

@SuppressWarnings("serial")
public class WiModelApp extends JFrame{
	public Hashtable<Integer, Object> R=new Hashtable<>();
	public static final int ID_CONSOLE=1;
	public WiModelApp(String title) {
		setTitle(title);
		setBounds(0, 0, 500, 500);
		setLayout(new FlowLayout());
		setBackground(Color.black);
		
		initComponent(this);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	private void initComponent(JFrame parent){
		JTextArea console=new JTextArea();
		console.setBounds(0, 0, parent.getWidth(), parent.getHeight());
		setId(ID_CONSOLE, console);
		parent.add(console);
		
	}
	public Object findViewById(int id){
		return R.get(id);
	}
	public void setId(int id,Object view){
		R.put(id, view);
	}
	public static void main(String[] args) {
		// Start GUI
		// test for xml parse
		long crtTime=System.currentTimeMillis();
		WiModelManager mng=WiModelManager.getInstance();
		mng.setTraceFile("./res/trace/wissim-trace.xml");
	try {
	    mng.parse();
	} catch (WiException ex) {
	}
		
		WiModelAdapter adapter=new WiModelAdapter();
		System.out.println("Time Parse: "+adapter.getMilliTimeParse()+"ms");
		System.out.println("Number of Nodes: "+mng.getListNodes().size());
		System.out.println("Number of Events: "+mng.getListEvents().size());
		System.out.println("Number of Packets: "+mng.getListPackets().size());
		System.out.println("========NODEs=========");
		for (WiObject node : mng.getListNodes()) {
			System.out.println(node.toString());
		}
		System.out.println("========EVENTs=========");
		for (WiObject event : mng.getListEvents()) {
			System.out.println(event.toString());
		}
		System.out.println("========PACKETs=========");
		for (WiObject packet : mng.getListPackets()) {
			System.out.println(packet.toString());
			
		}
		System.out.println(adapter.getMilliTimeParse());
		long endTime=System.currentTimeMillis();
		
		System.out.println("time process:"+(endTime-crtTime));
	}
}
